//
//  BasicTableViewController.m
//  CHVolunteer
//
//  Created by 李晓俊 on 2018/12/20.
//  Copyright © 2018 李晓俊. All rights reserved.
//

#import "BasicTableViewController.h"
#import "BasicNavigationController.h"

#import "MTLoginHomeVC.h"

typedef void(^RefreshBlock)();//刷新的block
@interface BasicTableViewController ()

@end

@implementation BasicTableViewController
{
    RefreshBlock _refreshBlock;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.showsVerticalScrollIndicator = NO;
    [self initVariable];
    self.tableView.backgroundColor = KBackColor;
     ///调用接口
    //    [self responseFrominterface];
    [self CreateNav];
    self.page = 1;
}

-(void)initVariable
{
    
}
-(void)UIinitWithModel{
    
}

-(void)CreateNav
{
    //默认返回事件
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc ]initWithImage:[UIImage imageWithOriginalName:@"返回黑色"] style:UIBarButtonItemStyleDone target:self action:@selector(returnAction)];
    self.navigationItem.leftBarButtonItem = leftBtn;
}
- (void)returnAction {
    [self.navigationController popViewControllerAnimated:YES];
}

-(MJRefreshGifHeader *)RefeshOfimages:(void(^)())block
{
    NSArray *images = @[[UIImage imageNamed:@"1"],
                        [UIImage imageNamed:@"2"],
                        [UIImage imageNamed:@"3"],
                        [UIImage imageNamed:@"4"],
                        [UIImage imageNamed:@"5"],
                        [UIImage imageNamed:@"6"],
                        [UIImage imageNamed:@"7"],
                        [UIImage imageNamed:@"8"],
                        [UIImage imageNamed:@"9"],
                        [UIImage imageNamed:@"10"],
                        [UIImage imageNamed:@"11"]
                        ];
    
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    _refreshBlock = block;
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
     // 隐藏状态
    header.stateLabel.hidden = YES;
    // 设置普通状态的动画图片
    [header setImages:images forState:MJRefreshStateIdle];
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [header setImages:images forState:MJRefreshStatePulling];
    // 设置正在刷新状态的动画图片
    [header setImages:images forState:MJRefreshStateRefreshing];
    // 设置header
    return header;
}
-(void)loadNewData
{
    _refreshBlock();
}



///调用接口
-(void)responseFrominterface{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

 
 
 
#pragma mark - 缺省页
-(void)createViewBynoMsgName2:(NSString *)msgName alertMsg:(NSString *)alertMsg alertMsg2:(NSString *)alertMsg2 {
    self.noMsgView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 170, kScreenWidth, kScreenHeight-170)];
    self.noMsgView2.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView2 addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.noMsgView2.mas_top).with.offset(kFit(125)+36);
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(63));
        make.height.equalTo(@(63));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_15;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    [self.noMsgView2 addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(kFit(350)));
    }];
    UILabel *label2 = [[UILabel alloc] init];
    label2.font = Font_12;
    label2.textColor = HEXCOLOR(0xC7C7C7);
    label2.textAlignment = NSTextAlignmentCenter;
    label2.text = alertMsg2;
    [self.noMsgView2 addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.noMsgView2.mas_centerX);
        make.width.equalTo(@(kFit(350)));
        make.height.equalTo(@15);
    }];
}


-(void)createHomeViewBynoMsgName3:(NSString *)msgName alertMsg:(NSString *)alertMsg{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 280, kScreenWidth, kScreenHeight-280)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(80)+36);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(63));
        make.height.equalTo(@(63));
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_14;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
    }];
}


-(void)createHomeViewBynoMsgName:(NSString *)msgName alertMsg:(NSString *)alertMsg withSize:(CGSize)size{
    self.noMsgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.noMsgView.backgroundColor = KBackColor;
    
    UIImageView *imageView = [[UIImageView alloc]  init];
    imageView.image = [UIImage imageNamed:msgName];
    [self.noMsgView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.centerY.equalTo(self.noMsgView.mas_centerY).with.offset(-100);
        make.top.equalTo(self.noMsgView.mas_top).with.offset(kFit(125)+36);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.mas_equalTo(size.width);
        make.height.mas_equalTo(size.height);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = Font_14;
    label.textColor = TextDescribeColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = alertMsg;
    label.numberOfLines = 2;
    [self.noMsgView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.noMsgView.mas_centerX);
        make.width.equalTo(@(kFit(255)));
    }];
}

- (void)logouTotLogin {
    UIWindow * window = [[UIWindow alloc] init];
    
    BasicNavigationController *nav = [[BasicNavigationController alloc]initWithRootViewController:GetViewControllerInStoryboard(@"Login", @"MTLoginHomeVC")];
    [self.window setRootViewController:nav];
    
    window.rootViewController = nav;
    self.window = window;
    [self.window makeKeyAndVisible];
}
 
@end
